<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
if(!in_array('tip_list',$QXARR))exit(noauth());
switch ($submitok) {
	case"alldel":
		$tmeplist = $list;
		if(empty($tmeplist))json_exit(array('flag'=>0,'msg'=>'请选择您要删除的信息'));
		if(!is_array($tmeplist))exit(JSON_ERROR);
		if(count($tmeplist)>=1){
			foreach($tmeplist as $value){$v=intval($value);
				$row2 = $db->ROW(__TBL_TIP__,"uid,content","id=".$v,'num');$uid= $row2[0];$content= $row2[1];
				$row2 = $db->ROW(__TBL_USER__,"nickname","id=".$uid,'num');$nickname= $row2[0];
				AddLog('批量删除【'.$nickname.'（uid:'.$uid.'）】消息通知(站内信)，内容->'.$content);
				$db->query("DELETE FROM ".__TBL_TIP__." WHERE id=".$v);
			}
		}
		json_exit(array('flag'=>1,'msg'=>'删除成功'));
	break;
}
if($session_kind == 'crm')$SQLGJ = " AND b.admid=".$session_uid;//认领红娘名下
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
</head>
<style>.box{min-width:1000px;padding:0}</style>
<body<?php echo (ifint($uid))?' class="body"':'';?>>
<div class="box">
	<?php if (!ifint($uid)){?>
	<div class="boxL">
        <?php if(CRMQX('tip_list')){?><a href="tip_list.php?uid=<?php echo $uid;?>" class='ed'>消息通知</a><?php }?>
        <?php if(CRMQX('chat_list')){?><a href="chat_list.php?uid=<?php echo $uid;?>">私信聊天</a><?php }?>
        <?php if(CRMQX('view_list')){?><a href="view_list.php?uid=<?php echo $uid;?>">谁看过我</a><?php }?>
        <?php if(CRMQX('gz_list')){?><a href="gz_list.php?uid=<?php echo $uid;?>">用户关注</a><?php }?>
        <?php if(CRMQX('hh_list')){?><a href="hh_list.php?uid=<?php echo $uid;?>">用户互换</a><?php }?>
        <?php if(CRMQX('u_bbs')){?><a href="u_bbs.php?uid=<?php echo $uid;?>">用户评价</a><?php }?>
        <?php if(CRMQX('u_endtime')){?><a href="u_endtime.php?uid=<?php echo $uid;?>">最新登录</a><?php }?>
	</div>
	<div class="boxR">
        <div class="topsearch">
            <form name="ZEAI_CN__form1" method="get" action="<?php echo SELF; ?>">
                <input name="Skey" type="text" id="Skey" maxlength="25" class="input size2 W200" placeholder="按接收方UID昵称/主动方UID" value="<?php echo $Skey; ?>">　
                <input name="Skey2" type="text" id="Skey2" maxlength="25" class="input size2 W150" placeholder="按通知内容" value="<?php echo $Skey2; ?>">　
                <input type="checkbox" name="hxhi" id="hxhi" class="checkskin" value="1"<?php echo ($hxhi == 1)?' checked':''; ?>><label for="hxhi" class="checkskin-label"><i class="i1"></i><b class="W80 S14">互相打招呼</b></label><input type="hidden" name="p" value="<?php echo $p;?>" /><button type="submit" class="btn size2"><i class="ico">&#xe6c4;</i> 搜索</button>
            </form>
            <div class="rbox">
                <a href="tip_list.php"<?php echo (empty($new))?" class='ed'":""; ?>>全部<?php
                if(empty($new)){
                    $rtt = $db->query("SELECT COUNT(*) FROM ".__TBL_TIP__." a,".__TBL_USER__." b WHERE a.uid=b.id".$SQLGJ);
                    $rowt = $db->fetch_array($rtt);
                    echo '<b>'.$rowt[0].'</b>';
                }?>
                </a>
                <a href="tip_list.php?new=1" <?php echo ($new == 1)?' class="ed"':''; ?>>未读<?php
                if($new == 1){
                    $rtt = $db->query("SELECT COUNT(*) FROM ".__TBL_TIP__." a,".__TBL_USER__." b WHERE a.new=1 AND a.uid=b.id".$SQLGJ);
                    $rowt = $db->fetch_array($rtt);
                    echo '<b>'.$rowt[0].'</b>';
                }?>
                </a>
            </div>
        </div>
	<?php }?>
        <!---->
        <?php
        $SQL = "";
        $Skey = trimhtml($Skey);
        if (ifint($Skey)){
            $SQL = " AND (b.id=$Skey OR a.senduid=$Skey) ";
        }elseif(!empty($Skey)){
            $SQL = " AND ( ( b.uname LIKE '%".$Skey."%' ) OR ( b.nickname LIKE '%".$Skey."%' ) OR ( b.nickname LIKE '%".urlencode($Skey)."%' ) )";
        }
        if(!empty($Skey2)){
            $SQL .= " AND ( a.content LIKE '%".$Skey2."%' )";
        }
        if (ifint($uid)){
            $SQL = " AND (a.uid=$uid) ";
            $_ADM['admPageSize']=8;
        }
        $SORT = " ORDER BY a.id DESC";
        
        if($hxhi==1){
            $SQL .= "AND a.uid=c.senduid AND a.senduid=c.uid";// GROUP BY a.uid
            $rt   = $db->query("SELECT a.*,b.sex,b.grade,b.nickname FROM ".__TBL_TIP__." a,".__TBL_TIP__." c,".__TBL_USER__." b WHERE a.kind=3 AND a.uid=b.id ".$SQL.$SQLGJ.$SORT." LIMIT ".$_ADM['admLimit']);
            //b.kind<>4 AND 
        }else{
            if($new==1)$SQL = " AND a.new=1 ";
            $rt = $db->query("SELECT a.*,b.sex,b.grade,b.nickname FROM ".__TBL_TIP__." a,".__TBL_USER__." b WHERE a.uid=b.id ".$SQL.$SQLGJ.$SORT."  LIMIT ".$_ADM['admLimit']);
        }
        $total = $db->num_rows($rt);
        if ($total <= 0 ) {
            echo "<div class='nodataico'><i></i>暂无内容符合";
            if (!ifint($uid))echo"<br><a class='aQINGed' href='javascript:history.back(-1)'>返回上一步</a>";
            echo "</div>";
        } else {
            $page_skin=2;$pagemode=3;$pagesize=$_ADM['admPageSize'];require_once ZEAI.'sub/page.php';
        ?>
        <form id="www_zeai_cn_FORM" method="get" action="<?php echo SELF; ?>">
        <table class="tablelist">
        <tr>
        <th width="20"><input type="checkbox" id="checkboxall1" class="checkskin checkboxall"><label for="checkboxall1" class="checkskin-label"><i class="i1"></i></label></th>
        <th width="70">ID</th>
        <th width="50">&nbsp;</th>
        <th width="180" align="left">发送方</th>
        <th width="50" align="left">&nbsp;</th>
        <th width="200" align="left">接收方</th>
        <th>内容</th>
        <th width="150">时间</th>
        </tr>
        <?php
        for($i=1;$i<=$pagesize;$i++) {
            $rows = $db->fetch_array($rt,'name');
            if(!$rows) break;
            $id = $rows['id'];$uidd = $rows['uid'];
            $uname = strip_tags($rows['uname']);
            $uname = str_replace($Skey,"<font color=red><b>".$Skey."</b></font>",$uname);
            $nickname = dataIO($rows['nickname'],'out');
            $nickname = str_replace($Skey,"<font color=red><b>".$Skey."</b></font>",$nickname);
            $sex       = $rows['sex'];
            $grade     = $rows['grade'];
            if(empty($rows['nickname'])){
                $nickname = $uname;
            }
            $new = $rows['new'];
            $senduid = $rows['senduid'];
            $kind = $rows['kind'];
            $new = $rows['new'];
            $senduid = $rows['senduid'];
            $content = trimhtml(dataIO($rows['content'],'out'));
            $content = str_replace($Skey2,"<font color=red><b>".$Skey2."</b></font>",$content);
            $addtime = YmdHis($rows['addtime']);
            $new_str = ($new == 1)?'<img src="images/new.gif">':'';
            switch ($kind) {
                case 1:$c = '【系统】';break;
                case 2:$c = '【礼物】';break;
                case 3:$c = '【招呼】';break;
                case 4:$c = '【红娘】';break;
                case 5:$c = '【推广】';break;
            }
            $content='<font class="tiaose">'.$c.'</font>'.$content;
        ?>
        <tr id="tr<?php echo $id;?>">
            <td width="20" height="40"><input type="checkbox" name="list[]" value="<?php echo $id; ?>" uid="<?php echo $uid; ?>" id="id<?php echo $id; ?>" class="checkskin"><label for="id<?php echo $id; ?>" class="checkskin-label"><i class="i1"></i></label>
            </td>
          <td width="70" class="C999"><label for="id<?php echo $id; ?>"><?php echo $id;?></label></td>
          <td width="50" class="C999"><?php echo $new_str; ?></td>
            <td width="180" align="left">
            <?php 
            $row2 = $db->ROW(__TBL_USER__,"sex,grade,nickname","id=".$senduid);
            if (!$row2){
                echo '系统';
            }else{
                $sex2      = $row2[0];
                $grade2    = $row2[1];
                $nickname2 = dataIO($row2[2],'out');
            ?><a href="<?php echo Href('crm_u',$senduid);?>">
                <?php
                    echo uicon($sex2.$grade2);
                    echo '<span class="middle">';
                    echo $nickname2."　<font class='S12 C999'>(uid：".$senduid.")</font>";
                    echo '</span>';
                    ?>
                </a>
            <?php }?>
            </td>
            <td width="50" align="left">
            <?php
            if ($hxhi == 1){
                echo '<i class="ico S18 Cccc">&#xe635;</i>';
            }else{
                echo '<i class="ico S18 Cccc">&#xe62d;</i>';
            }
            ?>
            </td>
          <td width="200" align="left"><a href="<?php echo Href('crm_u',$uidd);?>">
            <?php
            echo uicon($sex.$grade);
            echo '<span class="middle">';
            echo $nickname."　<font class='S12 C999'>(uid：".$uidd.")</font>";
            echo '</span>';
            ?>
          </a></td>
          <td align="left" class="S12"><?php echo $content; ?></td>
          <td width="150"><?php echo $addtime;?></td>
          </tr>
        <?php } ?>
        </table>
        </form>
        <?php }?>
		<!---->
	<?php if (!ifint($uid)){?></div><?php }?>
    <div class="clear"></div>
</div>

<?php if ($total > 0 ) {?>
<div class="listbottombox">
	<input type="checkbox" id="checkboxall2" class="checkskin checkboxall"><label for="checkboxall2" class="checkskin-label"><i class="i1"></i></label>　
    <button type="button" id="btndellist" class="btn size2 HEI2 disabled action">批量删除</button>　
    <button type="button" id="btnsend" value="" class="btn size2 disabled action" onClick="sendTipFn2(this);"><i class="ico">&#xe676;</i> 发送消息</button>
    <input type="hidden" name="submitok" id="submitok" value="" />
	<?php if ($total > $pagesize)echo '<div class="pagebox FR">'.$pagelist.'</div>'; ?>
</div>

<script>
var bg = '<?php echo $_Style['list_bg']; ?>',overbg = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';
o('btndellist').onclick = function() {
	allList({
		btnobj:this,
		url:'tip_list'+zeai.ajxext+'submitok=alldel',
		title:'批量删除',
		msg:'正在删除中...',
		ifjson:true,
		ifconfirm:true
	});	
}
</script>
<script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
<?php require_once 'bottomadm.php';?>